package com.joysuch.wwyt.list.controller;


import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.list.bean.BpListTypeDetailBean;
import com.joysuch.wwyt.list.bean.BpListTypeEditBean;
import com.joysuch.wwyt.list.entity.BpListType;
import com.joysuch.wwyt.list.service.BpListTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xiaoying
 * @since 2021-05-17
 */

@RestController
@RequestMapping("/bp/list/bp-list-type")
@Api(tags = "清单管理-类型管理")
@CrossOrigin
public class BpListTypeController {

    @Autowired
    private BpListTypeService bpListTypeService;


    @GetMapping("/listTree")
    @ApiOperation(value = "获取类型列表(树结构）")
    public ResultBean listTree() {

        return ResultBean.success(bpListTypeService.listTree());
    }

    @GetMapping("/listType")
    @ApiOperation(value = "获取类型列表")
    public ResultBean listType() {
        return ResultBean.success(bpListTypeService.listType());
    }


    @GetMapping("/getById")
    @ApiOperation(value = "根据Id查询类型", response = BpListTypeDetailBean.class)
    public ResultBean getById(@RequestParam Long id) {
        BpListTypeDetailBean bizType = bpListTypeService.getById(id);
        return ResultBean.success(bizType);
    }

    @RequiresPermissions("bp:list:bpListType:delete")
    @GetMapping("/deleteById")
    @ApiOperation(value = "根据Id删除类型")
    public ResultBean deleteById(@RequestParam Long id) {
        return bpListTypeService.deleteById(id);

    }

    @RequiresPermissions("bp:list:bpListType:save")
    @PostMapping("/save")
    @ApiOperation(value = "保存类型")
    public ResultBean save(@RequestBody BpListTypeEditBean bean) {

        return bpListTypeService.save(bean);

    }

}

